package com.neusoft.neuiotms.dcam.fixed.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import com.neusoft.neuiotms.dcam.common.model.Location;
import com.neusoft.neuiotms.dcam.common.model.Manufacturer;
import com.neusoft.neuiotms.dcam.fixed.model.enums.InventoryDutyResultStatus;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
@Table(name = "neuiot_inventory_result")
@org.hibernate.annotations.Table(appliesTo = "neuiot_inventory_result", comment = "盘点结果表")
public class InventoryResult extends AbstractAuditModel {

    private static final long serialVersionUID = 1L;

    @NotBlank(message = "资产名不能为空")
    @Length(max = 255, message = "资产名不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '资产名称'")
    private String name;

    @Length(max = 255, message = "固资编号不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '资产编号'")
    private String code;

    @NotNull(message = "资产类型不能为空")
    @ManyToOne
    private AssetType type;

    @ManyToOne(fetch = FetchType.LAZY)
    private Contract contract;

    @ManyToOne
    private Location location;

    //    @Enumerated(EnumType.STRING)
    //    @NotNull(message = "资产状态不能为空")
    //    @Column(length = 255, nullable = false)
    //    @Comment("varchar(255) COMMENT '资产状态'")
    //    private AssetStatus status = AssetStatus.idle;

    @NotNull(message = "资产状态不能为空")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) COMMENT '资产状态'")
    private String status = "idle";

    //    @Enumerated(EnumType.STRING)
    //    @NotNull(message = "资产来源不能为空")
    //    @Column(length = 255, nullable = false)
    //    @Comment("varchar(255) COMMENT '资产来源'")
    //    private AssetSource source = AssetSource.purchase;

    @NotNull(message = "资产来源不能为空")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) COMMENT '资产来源'")
    private String source = "purchase";

    /** 使用人ID */
    @Column(length = 20, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '使用人ID'")
    private String userId;

    /** 使用人姓名 */
    @Length(max = 255, message = "使用人不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '使用人'")
    private String userName;

    /** 使用部门 */
    @Length(max = 255, message = "使用部门不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '使用部门ID'")
    private String orgId;

    /** 使用部门名称 */
    @Length(max = 255, message = "使用部门不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '使用部门名称'")
    private String orgName;

    /** 产品 */
    @ManyToOne
    private Product product;

    /** 供应商 */
    @ManyToOne
    private Manufacturer manufacturer;

    /** 维保 */
    @OneToOne(cascade = CascadeType.ALL)
    private Maintenance maintenance;

    /** 计量单位 */
    @Length(max = 255, message = "使用人不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '计量单位'")
    private String measureUnit;

    /** 序列号 */
    @Length(max = 255, message = "序列号不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '序列号'")
    private String sequence;

    /** 金额 */
    @Column(length = 255, nullable = true)
    @Comment("double(255,2) COMMENT '金额'")
    private Double money;

    /** 使用期限 */
    @Column(length = 255, nullable = true)
    @Comment("double(255,2) COMMENT '使用期限（月）'")
    private Double month;

    /** 资产ID */
    @Column(nullable = true)
    @Comment("bigint(20) COMMENT '资产ID'")
    private Long assetId;

    /** 使用人ID(变更) */
    @Column(length = 20, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '使用人ID(变更)'")
    private String updateUserId;

    /** 使用人姓名(变更) */
    @Length(max = 255, message = "使用人不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '使用人(变更)'")
    private String updateUserName;

    /** 使用部门(变更) */
    @Length(max = 255, message = "使用部门不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '使用部门编码(变更)'")
    private String updateOrgCode;

    /** 使用部门名称 (变更) */
    @Length(max = 255, message = "使用部门不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '使用部门名称(变更)'")
    private String updateOrgName;

    /** 位置(变更) */
    @ManyToOne
    private Location updateLocation;

    /** 盘点备注 */
    @Column(length = 225, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '盘点备注'")
    private String note;

    /** 盘点结果状态 */
    @Enumerated(EnumType.STRING)
    @NotNull(message = "盘点结果状态不能为空")
    @Comment("varchar(255) NOT NULL COMMENT '盘点结果状态'")
    private InventoryDutyResultStatus dutyResultStatus = InventoryDutyResultStatus.wait;

    /** 关联盘点任务 */
    @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST }, fetch = FetchType.LAZY)
    InventoryDuty inventoryDuty;

    /** 扩展属性1 */
    @Length(max = 255, message = "不能超过{max}位")
    @Column(length = 255, nullable = true)
    private String ext1;

    /** 扩展属性2 */
    @Length(max = 255, message = "不能超过{max}位")
    @Column(length = 255, nullable = true)
    private String ext2;

    /** 扩展属性3 */
    @Length(max = 255, message = "不能超过{max}位")
    @Column(length = 255, nullable = true)
    private String ext3;

    /** 扩展属性4 */
    @Length(max = 255, message = "不能超过{max}位")
    @Column(length = 255, nullable = true)
    private String ext4;

    /** 扩展属性5 */
    @Length(max = 255, message = "不能超过{max}位")
    @Column(length = 255, nullable = true)
    private String ext5;
}
